<?php
/**
 * Created by PhpStorm.
 * User: 12133
 * Date: 2025/6/23
 * Time: 17:25
 */

namespace app\tab;
use app\model\Nav AS model;

class Nav{
    protected $tab = [
        'list', 'tree'
    ];
    public function list($html){
        $pattern = '/\{nav\s+action="([^"]+)"\s+level="([^"]+)"\}(.*?)\{\/nav\}/s';
        if (preg_match($pattern, $html, $matches)) {
            // 提取标签名和属性
            $tagName = $matches[1]; // nav
            $listName = $matches[2]; // list
            $level = $matches[3];   // 1
            // 提取中间的内容
            $content = $matches[4]; // 这是要提取的内容
        }
        $list = model::where('level',$level - 1)->select();
        $string = '';
        foreach ($list AS $key => $value){
            $string .= $content;
            foreach ($value AS $index => $item)
                $string = str_replace('{$'.$index.'}',$item,$string);
        }
        // 输出结果
        echo "标签名: $tagName\n";
        echo "列表名: $listName\n";
        echo "层级: $level\n";
        echo "内容: $content\n";

    }
    public function tree(){
        $list = model::select();
        $list = getTree($list);
        dd($list);
    }
}